package org.summerframework.component.security.config;

import org.summerframework.component.security.spring.DefaultRoleAnnotationSecurityMetadataSourceHandler;
import org.summerframework.component.security.spring.DefaultRoleServiceSupport;
import org.summerframework.component.security.spring.SecurityRoleService;
import org.summerframework.component.security.spring.SecurityRoleServiceImpl;
import org.summerframework.component.security.spring.access.RoleAnnotationSecurityMetadataSourceHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 石超
 * @version v1.0.0
 */
@Configuration
@ConditionalOnClass(SecurityRoleService.class)
public class SpringSecurityConfiguration {

    @Bean
    public SecurityRoleService securityRoleService() {
        return new SecurityRoleServiceImpl();
    }

    @Bean
    public DefaultRoleServiceSupport defaultRoleServiceSupport() {
        return new DefaultRoleServiceSupport();
    }

    @Bean
    @ConditionalOnProperty(name = "application.check", havingValue = "true")
    public RoleAnnotationSecurityMetadataSourceHandler roleAnnotationSecurityMetadataSourceHandler() {
        return new DefaultRoleAnnotationSecurityMetadataSourceHandler();
    }
}
